**** Chilean replication copyright Lydia Tiede @2019
*/Do.Chile.ReplicationFile.september1.2019.Final.do
*To use with :  Chile.replication.data.FINAL.august 31, 2019
***Variable names
*vote_unc2 = Dependent variable for judges' vote for unconstitutionality
*pres_appt = Presidential appointee
*leg_appt = Legislative appointee
*NE_appt = appointed by non-elected institution (CSN or Supreme Court)(base group)
*left_appt = Concertacion associated judge
*right_appt =  Right coalition associated judge
*noparty_appt = judge not associated with party (nonpartisan)(base group)
*tenure  = tenure or years on the bench
* req = requerimiento
*sopnew = separation of powers case
*subnew = subnational government case
*rightsnew = rights case
*year09 = Composition change 1
*year12 = composition change 2
**Description of panel effects variables
*presapptavg_other = Average other presidential appointees 
*legapptavg_other = Average other legislative appointees
*LTapptavg_other = Average other Concertacion (left) associated judge
*RTapptavg_other = Average other Right associated judges

*rol_para  = each unique identifier for decisional paragraphs within cases
*rol_2  = each unique identifier for each full case used to use for random intercept

*** Creation of above panel effects variables
*encode rol_para, gen(rolC)
*egen presappt_sum = sum(pres_appt), by(rolC)
*egen legappt_sum= sum(leg_appt), by(rolC)

*egen RTappt_sum= sum(right_appt), by(rolC)

*egen LTappt_sum= sum(left_appt), by(rolC)

*generate totaljminus1=totalj_count-1

*gen presapptavg_other= (presappt_sum - pres_appt)/totaljminus1
*gen legapptavg_other= (legappt_sum - leg_appt)/totaljminus1
*gen RTapptavg_other= (RTappt_sum - right_appt)/totaljminus1
*gen LTapptavg_other= (LTappt_sum - left_appt)/totaljminus1





***CODE FOR MAIN MODELS IN TEXT.  TABLE 2
***EQUATION 1:  INSTITUTIONS ALONE
*** random intercept by case, which is rol_2, not individual decisional paragraph which is rol_para
xtset rol_2
xtprobit vote_unc2  pres_appt leg_appt     tenure   req sopnew subnew rightsnew  presapptavg_other legapptavg_other   year09 year12 , i(rol_2) vce(robust) nolog
estat ic


***EQUATION 2:  PARTY ALONE
xtset rol_2
xtprobit vote_unc2  left_appt right_appt   tenure   req sopnew subnew rightsnew   LTapptavg_other RTapptavg_other  year09 year12 , i(rol_2) vce(robust) nolog
estat ic

***EQUATION 3:  INSTITUTIONS AND PARTY
xtset rol_2
xtprobit vote_unc2  pres_appt leg_appt  left_appt right_appt   tenure   req sopnew subnew rightsnew presapptavg_other legapptavg_other  LTapptavg_other RTapptavg_other year09 year12  ,  i(rol_2) vce(robust) nolog
estat ic


***Predicted probabilities for above models main text Table 2
***EQUATION 1:  INSTITUTIONS ALONE
xtset rol_2
xtprobit vote_unc2  pres_appt leg_appt     tenure   req sopnew subnew rightsnew  presapptavg_other legapptavg_other   year09 year12 , i(rol_2) vce(robust) nolog
margins, dydx(pres_appt) atmeans
margins, dydx(leg_appt) atmeans
margins, dydx(req) atmeans
margins, dydx(sopnew) atmeans
margins, dydx(subnew) atmeans
margins, dydx(rightsnew) atmeans
margins, dydx(year09) atmeans
margins, dydx(year12) atmeans
margins, at(tenure=(0(1)11))atmeans
margins, at(presapptavg_other=(0(.10).43)) atmeans
margins, at(legapptavg_other=(.14(.10) .57)) atmeans

***EQUATION 2:  PARTY ALONE
xtset rol_2
xtprobit vote_unc2  left_appt right_appt   tenure   req sopnew subnew rightsnew   LTapptavg_other RTapptavg_other  year09 year12 , i(rol_2) vce(robust) nolog
margins, dydx(left_appt) atmeans
margins, dydx(right_appt) atmeans
margins, dydx(req) atmeans
margins, dydx(sopnew) atmeans
margins, dydx(subnew) atmeans
margins, dydx(rightsnew) atmeans
margins, dydx(year09) atmeans
margins, dydx(year12) atmeans
margins, at(tenure=(0(1)11))atmeans
margins, at(LTapptavg_other=(.125(.10).714)) atmeans
margins, at(RTapptavg_other=(0(.10) .57)) atmeans

***EQUATION 3:  INSTITUTIONS AND PARTY
xtset rol_2
xtprobit vote_unc2  pres_appt leg_appt  left_appt right_appt   tenure   req sopnew subnew rightsnew presapptavg_other legapptavg_other  LTapptavg_other RTapptavg_other year09 year12  ,  i(rol_2) vce(robust) nolog
margins, dydx(pres_appt) atmeans
margins, dydx(leg_appt) atmeans
margins, dydx(left_appt) atmeans
margins, dydx(right_appt) atmeans
margins, dydx(req) atmeans
margins, dydx(sopnew) atmeans
margins, dydx(subnew) atmeans
margins, dydx(rightsnew) atmeans
margins, dydx(year09) atmeans
margins, dydx(year12) atmeans
margins, at(tenure=(0(1)11))atmeans
margins, at(presapptavg_other=(0(.10).43)) atmeans
margins, at(legapptavg_other=(.14(.10) .57)) atmeans
margins, at(LTapptavg_other=(.11(.10).714)) atmeans
margins, at(RTapptavg_other=(0(.10) .57)) atmeans

***ROBUSTNESS CHECKS CHILE FOUND IN SUPPLEMENTARY MATERIALS.
****Supplemental materials.  Table 2.1.  Chile CT with tenure as only judge level variable
xtset rol_2
xtprobit vote_unc2      tenure   req sopnew subnew rightsnew  presapptavg_other legapptavg_other   year09 year12 , i(rol_2) vce(robust)
estat ic

****Supplemental materials.  Table 2.3.  Chile Ct with nonpartisan judges removed
*/exclude nonpartisan judges completely... base group is aligned
*/noparty_appt == nonpartisan judges... I turn this to 0 to eliminate them from the analysis  
xtset rol_2
xtprobit vote_unc2  pres_appt leg_appt   right_appt    tenure   req sopnew subnew rightsnew     presapptavg_other legapptavg_other RTapptavg_other year09 year12 if noparty_appt==0, i(rol_2) vce(robust) nolog

*/exclude nonpartisan judges completely... base group is oppos
xtset rol_2
xtprobit vote_unc2  pres_appt leg_appt left_appt   tenure   req sopnew subnew rightsnew     presapptavg_other legapptavg_other LTapptavg_other   year09 year12 if noparty_appt==0, i(rol_2) vce(robust) nolog


****Supplemental materials.  Table 2.4.  Chile CT, with variables for appointer and political affiliations (suggested by Reviewer #1)
*/liberal nominated by leg
generate LEGliberal=0
replace LEGliberal=1 if leg_appt==1 & left_appt==1

*/liberal nominated by pres
generate PRESlib=0
replace PRESlib=1 if pres_appt==1 & left_appt==1

*/liberal nonminated by supreme court or CSN
generate SCSNliberal=0
replace SCSNliberal=1 if NE_appt==1 & left_appt==1
 
*/right nominated by leg
generate LEGright=0
replace LEGright=1 if leg_appt==1 & right_appt==1

*/liberal nominated by pres
generate PRESright=0
replace PRESright=1 if pres_appt==1 & right_appt==1


xtset rol_2
xtprobit vote_unc2   PRESlib PRESright LEGliberal LEGright   SCSNliberal     tenure   req sopnew subnew rightsnew  LTapptavg_other RTapptavg_other  presapptavg_other legapptavg_other   year09 year12 , i(rol_2) vce(robust) nolog


*keep rol_para rol_2 tipo judges_name rolC vote_unc2 totalj_count totaljminus1 pres_appt leg_appt  left_appt right_appt   tenure   req sopnew subnew rightsnew presapptavg_other legapptavg_other  LTapptavg_other RTapptavg_other year09 year12 noparty_appt  NE_appt year mydate
